<template>
  <!-- #ifdef H5 -->
  <component
    :is="computedContentComponent"
    :meta-item="curMetaItem"
    :meta-item-list="metaItemList"
    :common-attr="commonAttr"
    :row-idx="rowIdx"
    :col-idx="colIdx"
    :row-data="rowData"
    :table-body-data="tableBodyData"
    :form-data="formData"
    :item-submit-config="itemSubmitConfig"
    :meta-dynmic-config="curMetaDynmicConfig"
    :vm-template-config="vmTemplateConfig"
  ></component>
  <!-- #endif -->
</template>
<script setup>
import { onUpdated, toRefs, computed, useAttrs } from "vue";

import metaTypeToComponentNameMaps from "./useMetaTypeToCompNameMaps"
//
const props = defineProps({
  metaItem: {
    type: Object,
    required: true,
  },
  metaItemList: {
    type: Array,
  },
  commonAttr: {
    type: Object,
    default: () => ({}),
  },
  itemSubmitConfig: {
    type: Object,
    default: () => ({
      submitStyle: "Manual",
      allowAutoSubmit: false,
    }),
  },
  metaDynmicConfig: {
    type: Object,
  },
  cellForceMetaConfigMapping: {
    type: Object,
    default: () => ({}),
  },
  vmTemplateConfig: {
    type: Object,
  },
  //表格专用 开始
  rowIdx: {
    type: [Number, Object],
    default: () => null,
  },
  colIdx: {
    type: [Number, Object],
    default: () => null,
  },
  rowData: {
    type: Object,
    default: () => null,
  },
  tableBodyData: {
    type: Object,
    default: () => null,
  },
  //表格专用 结束
  //表单专用 开始
  formData: {
    type: Object,
    default: () => null,
  },
  //表单专用 结束
});

const cellForceMetaConfigMappingKeys = computed(() => {
  return Object.keys(props.cellForceMetaConfigMapping);
});
const cellForceMetaConfigKey = computed(() => {
  if (props.rowIdx >= 0 && props.tableBodyData) {
    return `${props.tableBodyData[props.rowIdx]["id"]};${props.metaItem.key}`;
  } else {
    return null;
  }
});
const isUseForceMetaConfig = computed(() => {
  return cellForceMetaConfigMappingKeys.value.includes(
    cellForceMetaConfigKey.value
  );
});
const curMetaItem = computed(() => {
  return isUseForceMetaConfig.value
    ? props.cellForceMetaConfigMapping[cellForceMetaConfigKey.value]
        .staticConfig
    : props.metaItem;
});
const curMetaDynmicConfig = computed(() => {
  return isUseForceMetaConfig.value
    ? props.cellForceMetaConfigMapping[cellForceMetaConfigKey.value]
        .dynmicConfig
    : props.metaDynmicConfig;
});
const computedContentComponent = computed(() => {
  return metaTypeToComponentNameMaps[curMetaItem.value.type];
});
</script>
